var t = require("../../../@babel/runtime/helpers/interopRequireDefault"), a = require("../../../@babel/runtime/helpers/defineProperty"), o = t(require("../../tim-wx-sdk/tim-wx")), e = getApp();

Page({
    data: {
        language: "",
        roomid: "",
        show2: !1,
        show3: !1,
        taideRoom: "",
        tim: "",
        lasttime: "",
        messageList: [],
        messagesTop: 0,
        active: 0,
        now_goods: "",
        speak: {
            memberAvatar: "",
            nickName: "",
            index: "",
            memberId: ""
        },
        shiftout: {
            memberAvatar: "",
            nickName: "",
            index: "",
            memberId: ""
        },
        chatBanList: [],
        roomBanList: [],
        chatBanisLoadMore: !0,
        chatBanpage: 1,
        chatBantotal_page: 0,
        roomBanisLoadMore: !0,
        roomBanpage: 1,
        roomBantotal_page: 0,
        liveBol: !0,
        video_url: "",
        isLivePK: !1,
        livePKData: {},
        livePKSrc: ""
    },
    onLoad: function(t) {
        t.roomid && this.setData({
            roomid: t.roomid
        }), this.getsdkappid();
    },
    logout: function() {
        this.data.tim.logout().then(function(t) {
            console.log(t.data);
        }).catch(function(t) {
            console.warn("logout error:", t);
        });
    },
    stopcomments: function(t) {
        var a = t.currentTarget.dataset.index, o = t.currentTarget.dataset.memberid;
        this.setData({
            speak: {
                memberAvatar: this.data.messageList[a].memberAvatar,
                nickName: this.data.messageList[a].nickName,
                index: a,
                memberId: o
            },
            show2: !0
        });
    },
    speakaffirmbtn: function(t) {
        var o = t.currentTarget.dataset.index, s = t.currentTarget.dataset.memberid, n = this, i = e.getNetAddresss("plugin.room.frontend.anchor-aide.chat-ban");
        e._postNetWork({
            url: i,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                member_id: s
            },
            success: function(t) {
                var e, s, i = t.data;
                1 == i.result ? (wx.showToast({
                    icon: "none",
                    title: "禁言成功",
                    duration: 1500
                }), n.setData((a(e = {}, "messageList[" + o + "].show", !1), a(e, "show2", !1), 
                e))) : (wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                }), n.setData((a(s = {}, "messageList[" + o + "].show", !1), a(s, "show2", !1), 
                s)));
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    speakcancelbtn: function(t) {
        var o, e = t.currentTarget.dataset.index;
        this.setData((a(o = {}, "messageList[" + e + "].show", !1), a(o, "show2", !1), o));
    },
    liftBanBtn: function(t) {
        var a = t.currentTarget.dataset.index, o = t.currentTarget.dataset.memberid, s = this.data.chatBanList[a].nickname, n = this.data.chatBanList, i = this, r = e.getNetAddresss("plugin.room.frontend.anchor-aide.chat-reply");
        e._postNetWork({
            url: r,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                member_id: o
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (wx.showToast({
                    icon: "none",
                    title: "已将" + s + "解除禁言",
                    duration: 1500
                }), n.splice(a, 1), i.setData({
                    chatBanList: n
                })) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    recoverBnt: function(t) {
        var a = t.currentTarget.dataset.index, o = t.currentTarget.dataset.memberid, s = this.data.roomBanList, n = this, i = e.getNetAddresss("plugin.room.frontend.anchor-aide.room-reply");
        e._postNetWork({
            url: i,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                member_id: o
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (wx.showToast({
                    icon: "none",
                    title: "该会员已恢复",
                    duration: 1500
                }), s.splice(a, 1), n.setData({
                    roomBanList: s
                })) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    kickingPlayerBtn: function(t) {
        var a = t.currentTarget.dataset.index, o = t.currentTarget.dataset.memberid;
        this.setData({
            shiftout: {
                memberAvatar: this.data.messageList[a].memberAvatar,
                nickName: this.data.messageList[a].nickName,
                index: a,
                memberId: o
            },
            show3: !0
        });
    },
    shiftoutAffirmbtn: function(t) {
        var o = t.currentTarget.dataset.index, s = t.currentTarget.dataset.memberid, n = this, i = e.getNetAddresss("plugin.room.frontend.anchor-aide.room-ban");
        e._postNetWork({
            url: i,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                member_id: s
            },
            success: function(t) {
                var e, s, i = t.data;
                1 == i.result ? (wx.showToast({
                    icon: "none",
                    title: "成功踢出直播间",
                    duration: 1500
                }), n.setData((a(e = {}, "messageList[" + o + "].show", !1), a(e, "show3", !1), 
                e))) : (wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                }), n.setData((a(s = {}, "messageList[" + o + "].show", !1), a(s, "show3", !1), 
                s)));
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    show2CloseBtn: function() {
        this.setData({
            show2: !1
        });
    },
    show3CloseBtn: function() {
        this.setData({
            show3: !1
        });
    },
    shiftoutCancelbtn: function(t) {
        var o, e = t.currentTarget.dataset.index;
        this.setData((a(o = {}, "messageList[" + e + "].show", !1), a(o, "show3", !1), o));
    },
    morebtn: function(t) {
        for (var o = t.currentTarget.dataset.index, e = 0; e < this.data.messageList.length; e++) this.setData(a({}, "messageList[" + e + "].show", !1));
        this.setData(a({}, "messageList[" + o + "].show", !0));
    },
    setActivebtn: function(t) {
        var a = t.currentTarget.dataset.num;
        this.setData({
            active: a
        }), 2 == a ? (this.setData({
            chatBanisLoadMore: !0,
            chatBanpage: 1,
            chatBantotal_page: 0
        }), this.getchatBanList()) : 3 == a && (this.setData({
            roomBanisLoadMore: !0,
            roomBanpage: 1,
            roomBantotal_page: 0
        }), this.getroomBanList());
    },
    getchatBanList: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.chat-ban-list");
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                page: this.data.chatBanpage
            },
            success: function(a) {
                var o = a.data;
                1 == o.result ? t.setData({
                    chatBanList: o.data.data,
                    chatBantotal_page: o.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    statechangePK: function(t) {
        var a = t.detail.code;
        console.log("拉取连麦:::", a), "2002" != a && "2002" != a || wx.hideLoading({});
    },
    errorPK: function(t) {
        wx.hideLoading({}), wx.showToast({
            title: "拉取连麦失败",
            icon: "success",
            duration: 2e3
        }), console.log("拉取连麦失败:::", t);
    },
    getroomBanList: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.room-ban-list");
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                page: this.data.roomBanpage
            },
            success: function(a) {
                var o = a.data;
                1 == o.result ? t.setData({
                    roomBanList: o.data.data,
                    roomBantotal_page: o.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    setgoods: function(t) {
        var a = t.currentTarget.dataset.index, o = this, s = "", n = "", i = o.data.taideRoom.goods[a];
        this.data.now_goods && i.id == this.data.now_goods.goods_id ? (s = "plugin.room.frontend.anchor-aide.cancel-explain", 
        n = e.getNetAddresss(s), e._postNetWork({
            url: n,
            showToastIn: !1,
            data: {
                id: o.data.roomid,
                goods_id: i.id
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (o.setData({
                    now_goods: ""
                }), wx.showToast({
                    icon: "none",
                    title: "取消成功",
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        })) : (s = "plugin.room.frontend.anchor-aide.explain-goods", n = e.getNetAddresss(s), 
        e._postNetWork({
            url: n,
            showToastIn: !1,
            data: {
                id: o.data.roomid,
                goods_id: i.id
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (o.setData({
                    "now_goods.goods_id": i.id
                }), wx.showToast({
                    icon: "none",
                    title: "设置成功",
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    getsdkappid: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.im.get-im-sdk");
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {},
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var s = {
                        SDKAppID: e.data.sdkappid
                    };
                    t.data.tim = o.default.create(s), t.data.tim.setLogLevel(0), t.chatEventList(), 
                    t.getaideRoom();
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    chatMyProfile: function() {
        var t = this;
        t.data.tim.getMyProfile().then(function(a) {
            console.log(a.data), a.data.nick || t.changeMyProfile();
        }).catch(function(t) {
            console.warn("getMyProfile error:", t);
        });
    },
    changeMyProfile: function() {
        this.data.tim.updateMyProfile({
            nick: this.data.taideRoom.userNickname,
            avatar: this.data.taideRoom.userAvatar
        }).then(function(t) {
            console.log(t.data);
        }).catch(function(t) {
            console.warn("updateMyProfile error:", t);
        });
    },
    chatEventList: function() {
        var t = this;
        t.data.tim.on(o.default.EVENT.SDK_READY, function(a) {
            t.chatMyProfile();
        }), t.data.tim.on(o.default.EVENT.MESSAGE_RECEIVED, function(a) {
            t.data.lasttime != a.data[0].time && (t.data.lasttime = a.data[0].time, a.data.forEach(function(a, e) {
                if (a.conversationType == o.default.TYPES.CONV_GROUP) {
                    var s = a;
                    if ("customPkGroup" == s.payload.extension) t.setData({
                        livePKData: JSON.parse(s.payload.description),
                        livePKSrc: t.data.roomData.play_url_rtmp.match(/(\S*)\/live\//)[1] + "/live/" + s.payload.description.streamid,
                        isLivePK: !0
                    }); else if ("customQuitPkGroup" == s.payload.extension) t.setData({
                        livePKData: {},
                        livePKSrc: "",
                        isLivePK: !1
                    }); else if ("TIMCustomElem" == s.type && "customText" == s.payload.extension) {
                        var n = t.data.messageList, i = JSON.parse(s.payload.description);
                        i.show = !1, n.push(i), t.setData({
                            messageList: n,
                            messagesTop: 1e3 * n.length
                        });
                    }
                }
            }));
        }), t.data.tim.on(o.default.EVENT.MESSAGE_REVOKED, function(t) {}), t.data.tim.on(o.default.EVENT.CONVERSATION_LIST_UPDATED, function(t) {}), 
        t.data.tim.on(o.default.EVENT.GROUP_LIST_UPDATED, function(t) {}), t.data.tim.on(o.default.EVENT.GROUP_SYSTEM_NOTICE_RECEIVED, function(t) {}), 
        t.data.tim.on(o.default.EVENT.PROFILE_UPDATED, function(t) {}), t.data.tim.on(o.default.EVENT.BLACKLIST_UPDATED, function(t) {}), 
        t.data.tim.on(o.default.EVENT.ERROR, function(t) {}), t.data.tim.on(o.default.EVENT.SDK_NOT_READY, function(t) {}), 
        t.data.tim.on(o.default.EVENT.KICKED_OUT, function(t) {
            wx.showToast({
                icon: "none",
                title: "您的IM被踢下线了",
                duration: 2e3
            });
        });
    },
    getaideRoom: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.room");
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                id: this.data.roomid
            },
            success: function(a) {
                var o = a.data;
                1 == o.result ? (t.setData({
                    taideRoom: o.data,
                    now_goods: o.data.now_goods
                }), o.data.status && 4 == o.data.status && t.setData({
                    liveBol: !1,
                    video_url: o.data.video_url
                }), o.data.voice_status && t.setData({
                    livePKData: o.data.voice_anchor,
                    livePKSrc: o.data.voice_anchor.play_url.play_url_rtmp,
                    isLivePK: !0
                }), setTimeout(function() {
                    t.chatLogin();
                }, 1e3)) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    chatLogin: function() {
        var t = this;
        t.data.tim.login({
            userID: t.data.taideRoom.userID.toString(),
            userSig: t.data.taideRoom.userSig
        }).then(function(a) {
            console.log(a.data), t.chatJoinGroup();
        }).catch(function(t) {
            console.warn("login error:", t);
        });
    },
    chatJoinGroup: function() {
        this.data.lastGroupId = this.data.taideRoom.groupId, this.data.tim.joinGroup({
            groupID: this.data.taideRoom.groupId,
            type: o.default.TYPES.GRP_CHATROOM
        }).then(function(t) {
            switch (t.data.status) {
              case o.default.TYPES.JOIN_STATUS_WAIT_APPROVAL:
                break;

              case o.default.TYPES.JOIN_STATUS_SUCCESS:
                console.log(t.data.group);
            }
        }).catch(function(t) {
            console.warn("joinGroup error:", t);
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        this.logout();
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        2 == this.data.active ? this.data.chatBanisLoadMore ? this.getchatBanMoreData() : console.log("没有更多数据") : 3 == this.data.active && (this.data.roomBanisLoadMore ? this.getroomBanMoreData() : console.log("没有更多数据"));
    },
    getchatBanMoreData: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.chat-ban-list");
        t.data.chatBanisLoadMore = !1, this.data.chatBanpage >= this.data.chatBantotal_page || (this.data.chatBanpage = this.data.chatBanpage + 1, 
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                page: this.data.chatBanpage
            },
            success: function(a) {
                var o = a.data;
                1 == o.result ? t.setData({
                    chatBanList: t.data.chatBanList.concat(o.data.data)
                }) : t.setData({
                    chatBanpage: t.data.chatBanpage - 1,
                    chatBanisLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    getroomBanMoreData: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.room-ban-list");
        t.data.roomBanisLoadMore = !1, this.data.roomBanpage >= this.data.roomBantotal_page || (this.data.roomBanpage = this.data.roomBanpage + 1, 
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                id: this.data.taideRoom.id,
                page: this.data.roomBanpage
            },
            success: function(a) {
                var o = a.data;
                1 == o.result ? t.setData({
                    roomBanList: t.data.roomBanList.concat(o.data.data)
                }) : t.setData({
                    roomBanpage: t.data.roomBanpage - 1,
                    roomBanisLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    onShareAppMessage: function() {}
});